<?php
/**
 * 全要素分析-贡献度分析
 * Created by PhpStorm.
 * User: yy
 * Date: 2019/4/24
 * Time: 14:42
 */

namespace app\api\controller;

use think\Controller;
use app\common\validate\environmentAnalysis\EnvironmentAnalysisContributeValidate;
use app\common\service\environmentAnalysis\EnvironmentAnalysisContributeService;

class EnvironmentAnalysisContribute extends BaseController
{
    /**
     * 获取全要素-贡献度分析左上侧table数据（目前只有电力焦化）
     * @author yy by 2019/4/24
     */
    public function getTableIndustry()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-06-01', 'end_time' => '2019-06-13', 'contribute_pollutant_name' => 'pm2.5', 'company_pollutant_name' => 'so2', 'region_id' => 53, 'station_id' => 0];
        $validate = new EnvironmentAnalysisContributeValidate();
        $result   = $validate->check($param, [], 'tableIndustry');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisContributeService = new EnvironmentAnalysisContributeService();
            $list                                 = $environmentAnalysisContributeService->getTableIndustry($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 获取指定行业下的企业table
     * @author yy by 2019/4/30
     */
    public function getTableCompany()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-28', 'end_time' => '2019-06-06', 'contribute_pollutant_name' => 'so2', 'company_pollutant_name' => 'so2', 'industry_id'=>'all', 'region_id' => 53, 'station_id' => 1];
        $validate = new EnvironmentAnalysisContributeValidate();
        $result   = $validate->check($param, [], 'tableCompany');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisContributeService = new EnvironmentAnalysisContributeService();
            $list                                 = $environmentAnalysisContributeService->getTableCompany($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 获取空气质量趋势图
     * @author yy by 2019/5/5
     */
    public function getAqiTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-01', 'end_time' => '2019-05-30', 'region_id' => 53, 'station_id' => 1];
        $validate = new EnvironmentAnalysisContributeValidate();
        $result   = $validate->check($param, [], 'aqiTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisContributeService = new EnvironmentAnalysisContributeService();
            $list                                 = $environmentAnalysisContributeService->getAqiTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 获取工业贡献度趋势
     * @author yy by 2019/5/14
     */
    public function getIsIndustryTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-25', 'end_time' => '2019-06-09', 'region_id' => 53, 'station_id' => 1, 'contribute_pollutant_name'=>'so2'];
        $validate = new EnvironmentAnalysisContributeValidate();
        $result   = $validate->check($param, [], 'isIndustryTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisContributeService = new EnvironmentAnalysisContributeService();
            $list                                 = $environmentAnalysisContributeService->getIsIndustryTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 行业贡献度趋势图
     * @author yy by 2019/5/14
     */
    public function getIndustryTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-10', 'end_time' => '2019-05-15', 'region_id' => 53, 'station_id' => 1, 'contribute_pollutant_name'=>'so2'];
        $validate = new EnvironmentAnalysisContributeValidate();
        $result   = $validate->check($param, [], 'industryTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisContributeService = new EnvironmentAnalysisContributeService();
            $list                                 = $environmentAnalysisContributeService->getIndustryTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

    /**
     * 企业贡献度趋势图
     * @author yy by 2019/5/15
     */
    public function getCompanyTrend()
    {
        $param = $this->request->param();
        # 模拟数据
//        $param    = ['start_time' => '2019-05-10', 'end_time' => '2019-05-14', 'region_id' => 53, 'station_id' => 1, 'contribute_pollutant_name'=>'so2', 'company_id'=>'10','industry_id'=>''];
        $validate = new EnvironmentAnalysisContributeValidate();
        $result   = $validate->check($param, [], 'companyTrend');
        if (!$result) {
            $this->error($validate->getError());
        }
        $list = [];
        try {
            $environmentAnalysisContributeService = new EnvironmentAnalysisContributeService();
            $list                                 = $environmentAnalysisContributeService->getCompanyTrend($param);
        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('成功', $list);
    }

}